package serviceset3

import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

import java.text.SimpleDateFormat

class OrderSpec extends Specification implements DomainUnitTest<Order> {

    def setup() {
    }

    def cleanup() {
    }

    void "test a valid properties"() {
        given:
        def params = [customer: "1#mars", goods: ["1#motor g"], datePaid: new Date()]

        when:
        def orderInstance = new Order(params)
        orderInstance.save()

        then:
        !orderInstance.hasErrors()
    }

    void "test an invalid properties"() {
        given:
        def params = [customer: "1#mars", goods: [], datePaid: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2099-12-12 12:12:12")]

        when:
        def orderInstance = new Order(params)
        orderInstance.save()

        then:
        orderInstance.hasErrors()
        orderInstance.errors.allErrors.size() == 2
    }
}
